﻿#pragma once

#include <QObject>
#include <QAbstractGraphicsShapeItem>
#include <QPointF>
#include <QPen>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene>
#include <QCursor>
#include <QKeyEvent>
#include <QList>
#include <QDebug>
enum ControlPointType
{
    CPT_Center = 0,
    CPT_Control,
};
class ControlItem : public QObject, public QAbstractGraphicsShapeItem
{
    Q_OBJECT
public:
    explicit ControlItem(QGraphicsItem* parent, QPointF p, ControlPointType type);
    QPointF getCurPoint(){return mCurPoint;}
    QPointF getPrePoint(){return mPrePoint;}
    qreal offsetX(){return mOffsetX;}
    qreal offsetY(){return mOffsetY;}
    void setPoint(QPointF p);

protected:
    virtual QRectF boundingRect() const override;
    virtual void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget) override;
    virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;   
    virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;

private:
    QPen mPen = this->pen();
    ControlPointType mPointType;
    QPointF mCurPoint;
    QPointF mPrePoint;
    qreal mOffsetX;
    qreal mOffsetY;
    QRectF mRect;
};
